#!/bin/python3
#-*- coding: utf-8 -*-
# my_install.py
# @author 刘秋
# @email lq@aqiu.info
# @description 
# @created 2020-04-04T09:50:34.149Z+08:00
# @last-modified 2020-04-05T16:53:02.462Z+08:00
#

import os
import shutil
import datetime
import numpy as np
import pandas as pd

path_list = ["G:\\"]

my_type_path={
    "压缩包":r"E:\Downloader\压缩包",
    "安装包":r"E:\Downloader\安装包",
    "文档":["pdf","docx","doc","xls","xlsx","xlsm","ppt","pptx"],
    "画图":["dwg","bak","stp","dxf"],
    "图片":["jpt","png","JPEG","JPG","PNG","psd"]
}

my_type_list={
    "压缩包":["zip","rar","7z","tgz","btw","bz2"],
    "安装包":["exe","msi"],
    "文档":["pdf","docx","doc","xls","xlsx","xlsm","ppt","pptx"],
    "画图":["dwg","bak","stp","dxf"],
    "图片":["jpt","png","JPEG","JPG","PNG","psd"]
}

def my_os_remove(path,name,folder_path):    
    try:
        shutil.move(os.path.join(path,name),folder_path)
    except shutil.Error as err:                        
        print(f"这个包{os.path.join(path,name)}有问题")
        print(err)
        new_time=datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
        new_name=str(new_time)+"_"+name
        os.rename(os.path.join(path,name),os.path.join(path,new_name))
        print(f"旧的名字:{name}==>>新的名字：{new_name}")
        my_os_remove(path,new_name,folder_path)
        raise err
        # if os.path.exists(os.path.join(path,name)):
        #     os.remove(os.path.join(path,name))

for path in path_list:
    for name in os.listdir(path):
        if os.path.isfile(os.path.join(path,name)):
            for i in my_type_list.keys():                
                if name.split(".")[-1] in my_type_list[i]:
                    print(name,"|=|",i)
                    folder_path=os.path.join(path,i)
                    if not os.path.exists(folder_path):
                        os.makedirs(folder_path)
                        print(f"{folder_path}创建成功")
                    my_os_remove(path,name,folder_path)

